php获取目录的大小
<?php
$dirname="haha";
echo exchange(getdirsize($dirname));
echo getdirsize($dirname);
// 获取文件夹大小的递归函数
function getdirsize($dirname) {
	if (file_exists($dirname)) {
		$handle=opendir($dirname);
		$size=0;
		while (($file=readdir($handle))!==false) {
			if ($file!='.'&&$file!='..') {
				if (is_dir("$dirname/$file")) {
					$size=$size+getdirsize("$dirname/$file");
				}else {
					$size=$size+filesize($dirname."/$file");
				}
				
			}
		}
		return $size;
	}else{
		return "file not exists";
	}
	
}
//文件大小换算的函数
function exchange($bytes) {
	if ($bytes<1024) {
		return round($bytes,2)."B";
	}elseif ($bytes>=1024&&$bytes<1024*1024){
		return round($bytes/1024,2)."KB";
	}elseif ($bytes>=1024*1024&&$bytes<1024*1024*1024){
		return round($bytes/1024/1024,2)."MB";
	}elseif ($bytes>=1024*1024*1024&&$bytes<1024*1024*1024*1024){
		return round($bytes/1024/1024/1024,2)."GB";
	}elseif ($bytes>=1024*1024*1024*1024){
		return round($bytes/1024/1024/1024/1024,2)."TB";
	}else {
		return "parameter has something wrong!";;
	}
}